<?php 
    global $shortname;
   if (is_front_page()){
       wp_deregister_script('jquery');
       ?>
        <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.min.js"></script>
       <?php
   }
?>	
        
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.masonry.min.js"></script>
	<script type="text/javascript">
		jQuery(window).load(function(){
			<?php if (get_option('thestyle_blog_style') == 'false') { ?>
				//jQuery('#content #boxes').masonry({ columnWidth: 122, animate: true });
			<?php } ?>
			jQuery('#footer-content').masonry({ columnWidth: 305, animate: true });
			
//			var $fixed_sidebar_content = jQuery('.sidebar-fixedwidth');
//			
//			if ( $fixed_sidebar_content.length ) {
//				var sidebarHeight = $fixed_sidebar_content.find('#sidebar').height(),
//					contentHeight = $fixed_sidebar_content.height();
//				if ( contentHeight < sidebarHeight ) $fixed_sidebar_content.css('height',sidebarHeight);
//			}
		});               
	</script>        
        <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/tmpl.min.js"></script>
        <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.ias.js"></script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/scrollpagination.js"></script>
        <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.esn.autobrowse.js"></script>
        <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jstorage.js"></script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/cufon-yui.js"></script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/League_Gothic_400.font.js"></script>
	<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.hoverIntent.minified.js"></script>
	
	
	<script type="text/javascript">
	//<![CDATA[
		//jQuery.noConflict();		
		jQuery(document).ready(function(){
                        "user strict";
			<?php if (get_option('thestyle_cufon') == 'on') { ?>
				<?php if (get_option('thestyle_color_scheme') == 'Gray') { ?>
					Cufon.replace('ul.nav a',{textShadow:'1px 1px 0px #fff', hover: { textShadow: '1px 1px 0px #fff' }})('h3.title',{textShadow:'1px 1px 0px #fff'})('.wp-pagenavi',{textShadow:'1px 1px 1px rgba(255,255,255,0.7)'});
				<?php } else { ?>
					Cufon.replace('ul.nav a',{textShadow:'1px 1px 1px #000', hover: { textShadow: '1px 1px 1px #000' }})('h3.title',{textShadow:'1px 1px 1px #000'})('.wp-pagenavi',{textShadow:'1px 1px 1px rgba(0,0,0,0.7)'});
				<?php } ?>
				Cufon.replace('#featured h2.title')('div.category a',{textShadow:'1px 1px 1px rgba(0,0,0,0.3)'})('span.month',{textShadow:'1px 2px 4px rgba(0,0,0,0.3)'})('h2.title a')('p.postinfo')('h3.widgettitle, #tabbed-area li a',{textShadow:'1px 1px 1px #fff'})('h3.infotitle, h1.title, .blog-title, .post-meta, h3#comments, span.fn, h3#reply-title span');
			<?php } ?>
			
			jQuery('ul.nav').superfish({ 
				delay:       200,                            // one second delay on mouseout 
				animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
				speed:       'fast',                          // faster animation speed 
				autoArrows:  true,                           // disable generation of arrow mark-up 
				dropShadows: false                            // disable drop shadows 
			});
			
			jQuery('ul.nav > li > a.sf-with-ul').parent('li').addClass('sf-ul');
			
			jQuery(".entry").hoverIntent({
				over: makeTall,
				timeout: 150,
				out: makeShort
			}); 
			
			var $tabbed_area = jQuery('#tabbed'),
				$tab_content = jQuery('.tab-content'),
				$all_tabs = jQuery('#all_tabs');
			
			if ($tabbed_area.length) {
				$tabbed_area.tabs({ fx: { opacity: 'toggle' } });
			};
					
			et_search_bar();
		
                        function makeTall(){ 
				jQuery('.entry').not(this).animate({opacity:0.3},150);
			}
			function makeShort(){ 
				jQuery('.entry').removeClass('active').animate({opacity:1},150);
			} 			
			<!---- Search Bar Improvements ---->
			function et_search_bar(){
				var $searchform = jQuery('#header div#search-form'),
					$searchinput = $searchform.find("input#searchinput"),
					searchvalue = $searchinput.val();
					
				$searchinput.focus(function(){
					if (jQuery(this).val() === searchvalue) jQuery(this).val("");
				}).blur(function(){
					if (jQuery(this).val() === "") jQuery(this).val(searchvalue);
				});
			}
			
			jQuery(".js ul.nav a, .js ul.nav ul a, .js ul.nav ul li, .js ul.nav li.sfHover ul, .js ul.nav li li.sfHover ul, .js div.category a, .js span.month, .js span.date, .js h2.title, .js p.postinfo, .js #tabbed-area li a, .js #sidebar h3.widgettitle, .js .wp-pagenavi span.current, .js .wp-pagenavi span.extend, .js .wp-pagenavi a, .js .wp-pagenavi span, .js #footer h3.title, .js .info-panel h3.infotitle, .js .post-text h1.title, .js .cufon-disabled .blog-title a, .js p.post-meta, .js h3#comments, .js span.fn, .js span.fn a, .js .commentmetadata span.month, .js .commentmetadata span.date").css('text-indent','0px');
			
			<?php if (get_option($shortname.'_disable_toptier') == 'on') echo('jQuery("ul.nav > li > ul").prev("a").attr("href","#");'); ?>
			
			jQuery('.entry').click(function(){
				window.location = jQuery(this).find('.title a').attr('href');
			});
			
			<?php if (get_option('thestyle_cufon') == 'on') { ?>
				Cufon.now();
			<?php } ?>
                        var _gaq = _gaq || [];    
                        var totalPages = parseInt($("#hidTotalPages").val());                        
                        var currentPage = 1;
                        if (currentPage < totalPages){
                            currentPage += 1;
                            var contentData = {
                                action: 'show_all_articles',
                                paged: currentPage,
                                totalPages: totalPages
                            };
                           jQuery.ias({
                                    container : "#boxes",
                                    item: ".entry",
                                    pagination: "#controllers div.wp-pagenavi",
                                    next: "#controllers div.wp-pagenavi .nextpostslink",
                                    offsetHeight: 440,
                                    onPageChange: function(pageNum, pageUrl, scrollOffset) {
                                    path = jQuery('<a/>').attr('href',pageUrl)[0].pathname.replace(/^[^\/]/,'/');
                                    _gaq.push(['_trackPageview', path]);
                                },
                                dataType: 'json',
                                ajaxUrl: '<?php echo admin_url('admin-ajax.php');?>',
                                loader: '<img src="<?php bloginfo('template_directory'); ?>/js/images/loader.gif"/>',
                                makeShort: function(){
                                    makeShort();
                                },
                                makeTall : function(){
                                    makeTall();
                                },
                                onComplete: function(data){
                                   var result = '';
                                   for(var i=0; i < data.length; i++){
                                      
                                      var post = data[i];
                                      var post_link = post.post_link;
                                      result += '<div class="entry small"><div class="thumbnail">';
                                      result += '<a href="'+post_link+'"><img src="'+post.thumbnail+'"/><span class="overlay"></span></a>';
                                      var catLinks = '<div class="category"><ul class="post-categories">';
                                      for(var j=0; j < post.categories.length; j++){
                                          var cate = post.categories[j];
                                          catLinks += '<li><a rel="category tag" title="View all posts in '+cate.name+'" href="'+cate.cate_link+'" style="text-indent: 0px;">'+cate.name+'</a></li>';
                                      }
                                      catLinks += '</ul></div>';
                                      result += catLinks;
                                      result += '<span class="month">'+post.month+'<span class="date">'+post.day+'</span></span>';
                                      result += '</div>';
                                       
                                      result += '<h2 class="title"><a href="'+post_link+'">'+post.post_title+'</a></h2>';
                                      result += '<p class="postinfo">'+post.posted_by+'</p>';
                                      result += '<div class="entry-content">';
                                      result += '<div class="bottom-bg">';
                                      result += '<div class="excerpt">';
                                      result += '<p>'+post.excerpt+'</p>';
                                      result += '<div class="textright">';
                                      result += '<a href="'+post_link+'" class="readmore"><span>&raquo;</span>&raquo;</a>';
                                      result += '</div>';
                                      result += '</div>';
                                      result += '</div>';
                                      result += '</div>';
                                      result += '</div>';                                                                                                                  
                                   }
                                   
                                   return result;
                                }
                            });/*
                            $('#boxes').scrollPagination({
                                'contentPage': '<?php echo admin_url('admin-ajax.php');?>', // the url you are fetching the results
                                'contentData': contentData, // these are the variables you can pass to the request, for example: children().size() to know which page you are
                                'scrollTarget': $(window), // who gonna scroll? in this example, the full window
                                'heightOffset': 640, // it gonna request when scroll is 10 pixels before the page ends
                                'beforeLoad': function(){ // before load function, you can display a preloader div                
                                },
                                'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements                                  
                                     $(elementsLoaded).fadeInWithDelay();                 
                                }
                                ,
                                'complete' : function(data){
                                   // alert(data);  
                                   var result = '';
                                   for(var i=0; i < data.length; i++){
                                      var post = data[i];
                                      var post_link = post.post_link;
                                      result += '<div class="entry small"><div class="thumbnail">';
                                      result += '<a href="'+post_link+'"><img src="'+post.thumbnail+'"/><span class="overlay"></span></a>';
                                      var catLinks = '<div class="category"><ul class="post-categories">';
                                      for(var j=0; j < post.categories.length; j++){
                                          var cate = post.categories[j];
                                          catLinks += '<li><a rel="category tag" title="View all posts in '+cate.name+'" href="'+cate.cate_link+'" style="text-indent: 0px;">'+cate.name+'</a></li>';
                                      }
                                      catLinks += '</ul></div>';
                                      result += catLinks;
                                      result += '<span class="month">'+post.month+'<span class="date">'+post.day+'</span></span>';
                                      result += '</div>';
                                       
                                      result += '<h2 class="title"><a href="'+post_link+'">'+post.post_title+'</a></h2>';
                                      result += '<p class="postinfo"></p>';
                                      result += '<div class="entry-content">';
                                      result += '<div class="bottom-bg">';
                                      result += '<div class="excerpt">';
                                      result += '<p>'+post.excerpt+'</p>';
                                      result += '<div class="textright">';
                                      result += '<a href="'+post_link+'" class="readmore"><span>&raquo;</span>&raquo;</a>';
                                      result += '</div>';
                                      result += '</div><!-- end .excerpt -->';
                                      result += '</div><!-- end .bottom-bg -->';
                                      result += '</div><!-- end .entry-content -->';
                                      result += '</div><!-- end .entry -->';
                                      
                                   }
                                   
                                   return result;
                                   //var results = tmpl('template-posts', data);                                    
                                      
                                    <?php if (get_option('thestyle_cufon') == 'on') { ?>
                                        Cufon.replace('#featured h2.title', {color: '#9A1D0D'})('div.category a',{textShadow:'1px 1px 1px rgba(0,0,0,0.3)'})('span.month',{textShadow:'1px 2px 4px rgba(0,0,0,0.3)'})('h2.title a', {color: '#9A1D0D'})('p.postinfo')('h3.widgettitle, #tabbed-area li a',{textShadow:'1px 1px 1px #fff'})('h3.infotitle, h1.title, .blog-title, .post-meta, h3#comments, span.fn, h3#reply-title span');
                                        Cufon.refresh();
                                    <?php } ?>
                                },
                                dataType:"json"
                            });*/
                        }
                        
                        // code for fade in element by element
                        $.fn.fadeInWithDelay = function(){
                            var delay = 0;
                            return this.each(function(){
                                $(this).delay(delay).animate({opacity:1}, 100);
                                delay += 100;
                            });
                        }; 
                        
                        /*$("#boxes").autobrowse(
                            {
                                url: function (offset)
                                {
                                    return "<?php echo admin_url('admin-ajax.php');?>";
                                },
                                postData : contentData,
                                template: function (response)
                                {   
                                   var result = '';
                                   for(var i=0; i < response.length; i++){
                                      var post = response[i];
                                      var post_link = post.post_link;
                                      result += '<div class="entry small"><div class="thumbnail">';
                                      result += '<a href="'+post_link+'"><img src="'+post.thumbnail+'"/><span class="overlay"></span></a>';
                                      var catLinks = '<div class="category"><ul class="post-categories">';
                                      for(var j=0; j < post.categories.length; j++){
                                          var cate = post.categories[j];
                                          catLinks += '<li><a rel="category tag" title="View all posts in '+cate.name+'" href="'+cate.cate_link+'" style="text-indent: 0px;">'+cate.name+'</a></li>';
                                      }
                                      catLinks += '</ul></div>';
                                      result += catLinks;
                                      result += '<span class="month">'+post.month+'<span class="date">'+post.day+'</span></span>';
                                      result += '</div>';
                                       
                                      result += '<h2 class="title"><a href="'+post_link+'">'+post.post_title+'</a></h2>';
                                      result += '<p class="postinfo"></p>';
                                      result += '<div class="entry-content">';
                                      result += '<div class="bottom-bg">';
                                      result += '<div class="excerpt">';
                                      result += '<p>'+post.excerpt+'</p>';
                                      result += '<div class="textright">';
                                      result += '<a href="'+post_link+'" class="readmore"><span>&raquo;</span>&raquo;</a>';
                                      result += '</div>';
                                      result += '</div><!-- end .excerpt -->';
                                      result += '</div><!-- end .bottom-bg -->';
                                      result += '</div><!-- end .entry-content -->';
                                      result += '</div><!-- end .entry -->';
                                    }
                                    return result;                                    
                                },                                
                                itemsReturned: function (response) { return response.length; },
                                offset: 0,                                
                                loader: '<div class="loader"></div>',
                                useCache: false,
                                expiration: 0,
                                sensitivity: 100
                            }
                        );*/
		});
	//]]>	
	</script>
         <script id="template-posts" type="text/x-tmpl">
             {% for (var i=0, post; post=o[i]; i++) { %}
                <div class="entry small" rel="loaded">
			<div class="thumbnail">
				<a href="{%=post.post_link%}">
					<img src="{%=post.thumbnail%}"/>
					<span class="overlay"></span>
				</a>
				<div class="category">
                                     {% for (var j=0, cate; post.categories[j]; j++){%}
                                        <a rel="category tag" title="View all posts in Portfolio" href="{%=cate.cate_link%}" style="text-indent: 0px;">{%=cate.name%}</a>
                                     
                                     {% } %}
                                </div>
				<span class="month">{%=post.month%}<span class="date">{%=post.day%}</span></span>
			</div> <!-- end .thumbnail -->	
			<h2 class="title"><a href="{%=post.post_link%}">{%=post.post_title%}</a></h2>
			<p class="postinfo"></p>
			<div class="entry-content">
				<div class="bottom-bg">
					<div class="excerpt">
						<p>{%=post.excerpt%}</p>
						<div class="textright">
							<a href="{%=post.post_link%}" class="readmore"><span>&raquo;</span>&raquo;</a>
						</div>
					</div><!-- end .excerpt -->
				</div><!-- end .bottom-bg -->
			</div><!-- end .entry-content -->
		</div><!-- end .entry -->
             {% } %}             
         </script>